<?php

use yii\db\Migration;

/**
 * Handles the creation of table `category`.
 */
class m180111_062437_create_coupon_category_table extends Migration
{

    /**
     * @inheritdoc
     * CREATE TABLE `coupon_category` (
     * `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
     * `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名称',
     * `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '标题',
     * `rate` decimal(8,2) NOT NULL COMMENT '中奖概率',
     * `group_id` int(11) NOT NULL COMMENT 'GROUP_ID',
     * `mark_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '标识ID',
     * `attend_num` int(11) NOT NULL COMMENT '助力人数',
     * `image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '图片',
     * `type` int(11) NOT NULL COMMENT '类型',
     * `status` smallint(6) NOT NULL COMMENT '状态',
     * `use_scene` tinyint(4) NOT NULL COMMENT '使用场景',
     * `created_at` int(11) NOT NULL COMMENT '创建时间',
     * `updated_at` int(11) NOT NULL COMMENT '更新时间',
     * `description` json DEFAULT NULL,
     * PRIMARY KEY (`id`),
     * UNIQUE KEY `coupon_cayegory_mark_id_unique` (`mark_id`)
     * ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
     */
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%coupon_category}}', [
            'id' => $this->primaryKey(),

            'title' => $this->string(100)->notNull()->comment("优惠券名称"),
            'mark_id' => $this->string(50)->notNull()->unique()->comment("标识ID"),
            'group_id' => $this->integer(11)->notNull()->comment("券号"),
            'origin_num' => $this->integer(10)->comment("优惠券发放数量"),
            'use_num' => $this->integer(10)->comment("优惠券领取数量"),
            'type' => $this->integer(10)->notNull()->comment("类型"),
            'image' => $this->string(255)->comment("优惠券图片"),
            'status' => $this->integer(6)->notNull()->comment("状态"),

            'created_at' => $this->integer(11)->comment("优惠券创建时间"),
            'updated_at' => $this->integer(11)->comment("更新时间"),

            'local_mark_id' => $this->string(255)->comment("本地标识")//促销活动券还是团购券
        ], $tableOptions);
        return true;
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('{{%coupon_category}}');
        return true;
    }
}
